package com.github.aaronshan.functions.string;

import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;

/**
 * @Auther: GGbond
 * @Date: 2020/3/21 09:14
 * @Description:
 */
@Description(name = "string_double"
        , value = "_FUNC_() - string to double"
        , extended = "Example:\n > select _FUNC_() from src;")
public class UDFStringToDouble extends UDF {
    DoubleWritable result = new DoubleWritable();

    public UDFStringToDouble() {
    }

    public DoubleWritable evaluate(Text text) {
        try{
            result.set(Double.parseDouble(text.toString()));
            return result;
        }catch (Exception e){
            return null;
        }
    }
}
